from tkinter import *
from tkinter.dialog import *
from tkinter import _cnfmerge

def reg():
    s1 = e1.get()
    s2 = e2.get()
    t1 = len(s1)
    t2 = len(s2)
    if s1 == '111' and s2 == '222':
        c['text'] = '登录成功'
    else:
        c['text'] = '用户名或密码错误'
        e1.delete(0, t1)
        e2.delete(0, t2)

def demo1():
    root = Tk()

    l = Label(root, text = '用户名：')
    l.grid(row = 0, column = 0, sticky = W)

    e1 = Entry(root)
    e1.grid(row = 0, column = 1, sticky = E)
    l2 = Label(root, text = '密码：')
    l2.grid(row = 1, column = 0, sticky = W)

    e2 = Entry(root)
    e2['show'] = '*'
    e2.grid(row = 1, column = 1, sticky = E)

    b = Button(root, text = '登录', command = reg)
    b.grid(row = 2, column = 1, sticky = E)

    c = Label(root, text = "")
    c.grid(row = 3)

    root.mainloop()

def demo2():
    root = Tk()
    menubar = Menu(root)
    fmenu = Menu(menubar)
    for item in ['新建', '打开', '保存', '另存为']:
        fmenu.add_command(label = item)

    emenu = Menu(menubar)
    for item in ['复制', '粘贴', '剪切']:
        emenu.add_command(label = item)

    vmenu = Menu(menubar)
    for item in ['默认视图', '新式视图']:
        vmenu.add_command(label = item)

    amenu = Menu(menubar)
    for item in ['版权信息', '其他说明']:
        amenu.add_command(label = item)

    menubar.add_cascade(label = "文件", menu = fmenu)
    menubar.add_cascade(label = '编辑', menu = emenu)
    menubar.add_cascade(label = '视图', menu = vmenu)
    menubar.add_cascade(label = '关于', menu = amenu)

    root['menu'] = menubar
    root.mainloop()

# def xin():
#     global root
#     Label(root, text='I love python').pack()
'''
def demo3():

    root = Tk()


    menubar = Menu(root)

    for x in ['vb', 'c', 'java', 'php']:
        menubar.add_command(label = x)

    menubar.add_command(label = 'python', command = xin)

    def pop(event):
        menubar.post(event.x_root, event.y_root)

    root.bind("<Button-3>", pop)
    root.mainloop()


def demo4():
    def xin():
        d = Dialog(None, title = '2014星星', text = '2014年度还满意吗？',
                   bitmap = DIALOG_ICON, default = 0, strings = ('不满意', '还可以', '很满意'))
        print(d.num)

    t = Button(None, text = '星星调查', command = xin)
    t.pack
    b = Button(None, text = '关闭', command = t.quit)
    b.pack
    t.mainloop()
'''

# if __name__ == '__main__':
#     # demo4()
#     def xin():
#         d = Dialog(None, title = '2014星星', text = '2014年度还满意吗？',
#                    bitmap = DIALOG_ICON, default = 0, strings = ('不满意', '还可以', '很满意'))
#         print(d.num)
#
#     t = Button(None, text = '星星调查', command = xin)
#     t.pack
#     b = Button(None, text = '关闭', command = t.quit)
#     b.pack
#     t.mainloop()

time1 = 10
time2 = 10
def xin1():
    global l, c1, time1
    if time1 % 2 == 0:
        time1 += 1
        l['text'] = '2014年'
    else:
        time1 += 1
        l['text'] = '2015年'

def xin2():
    global l, c2, time2
    if time2 % 2 == 0:
        time2 += 1
        l['text'] = '2016'
    else:
        time2 += 1
        l['text'] = '2017'

root = Tk()
c1 = Checkbutton(root, text = '星哥2014', command = xin1)
c1.pack
c2 = Checkbutton(root, text = '星哥2015', command = xin2)
c2.pack
l = Label(root, text = "   ")
l.pack()
root.mainloop()



